<template>
    <div class="login">
        <div class="register" @click=regiser()>注册账号</div>
  <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="用户名"
    placeholder="请输入账号/手机号"
    :rules="[{ required: true }]"
    autocomplete
  />
  <van-field
    v-model="password"
    type="password"
    placeholder="请输入密码"
    :rules="[{ required: true }]"
    autocomplete
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit">登录</van-button>
  </div>
</van-form>
    </div>
</template>
<script>
import {loginQuery} from "../service/index"
import Vue from 'vue';
import { Toast } from 'vant';
Vue.use(Toast);
export default {
  data() {
    return {
      username: '',
      password: '',
    };
  },
  methods: {
    async onSubmit() {
      let res=await loginQuery({mobile:this.username,password:this.password});
      console.log(res);
      if(res.status==200){
        if(res.data.code==200){
          this.$router.replace("/home")
          Toast('登录成功');
        }else{
          Toast(res.data.message);
        }
      }else{
        Toast('登录失败');
      }
    },
    regiser(){
      this.$router.push("/register")
    }
  },
};
</script>
<style scoped lang="scss">
.login{
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    .register{
        position: absolute;
        right: 20px;
        top: 220px;
        z-index: 100;
        color: rgb(81, 190, 226);
        font-weight: 700;

    }
    .van-form{
    margin-top: 50px;
    width: 90%;
    :deep(.van-field__control){
        margin: -7px;
    }
    .van-cell{
        border: 1px solid gray;
        height: 30px;
        margin: 0 20px;
        margin-bottom: 20px;
    }
}
.van-button--round {
    border-radius: 5px;
    position: absolute;
    bottom: 40px;
    width: 92%;
}
}

</style>
